
var IE = document.all?true:false
var tempX = 0;
var tempY = 0;

function loadTree(){
	loadXMLDoc('reporting?action=getItemsByParentId&id=0&random='+Math.random(),'getItemsByParentId');
	
}

function onNodeClicked(id){
	currentNode=id;
	goToPage("itemRead.jsp?id="+currentNode);
	if(d.hasChildren(id))
		return;

	loadXMLDoc('reporting?action=getItemsByParentId&id='+id+'&random='+Math.random(),'getItemsByParentId');
}



function goToPage(page) {
	document.getElementById("iframe").src = page;
}





function loadXMLDoc(url, action) {
	req = false;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest && !(window.ActiveXObject)) {
		try {
			req = new XMLHttpRequest();
		} catch (e) {
			req = false;
		}
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				req = false;
			}
		}
	}
	if (req) {

		req.onreadystatechange = processReqChange;
		req.open("GET",url, true);
		req.onreadystatechange = function() {//Call a function when the state changes.
			if (req.readyState == 4 && req.status == 200) {
				processReqChange(action);
			}
		}
		req.send(null);

	}
}
function processReqChange(action) {
	// only if req shows "loaded"
	////alert(req.readyState);
	
	if (req.readyState == 4) {
		// only if "OK"
		//alert(110);
		if (req.status == 200) {
			//alert(targetDiv);	
			var str=(Url.decode(req.responseText));
			//var str=unescape(req.responseText);
			//document.getElementById('debug').innerHTML= str;	
			
			 var doc = eval('(' +  str + ')'); 
			 
			if (action=='getItemsByParentId'){
				 for( i=0;i<doc.items.length;i++){
				       var name= doc.items[i].name;   
				       var id= doc.items[i].id; 
				       var parentId=doc.items[i].parentId; 
				       var name= doc.items[i].name;
				       var type= doc.items[i].type; 
				       var iconClosed= doc.items[i].iconClosed; 
				       var iconOpened= doc.items[i].iconOpened; 
				     //  mytree.add(1, 0, 'My node', 'node.html', 'node title', 'mainframe', 'img/musicfolder.gif');
				       d.add(id, parentId,name, 'javascript:onNodeClicked('+id+')',name,'',iconClosed,iconOpened);
				       d.openTo(parentId, false);
					     
				 }
				 
			
				 div=document.getElementById('dtree').innerHTML=d;
				
				 
			 }
			
		}

	} else {
			//alert("There was a problem retrieving the XML data:\n"+ req.statusText);
		}
	

	
}





